-# locals: risky_attribute, id_prefix, seen_ids

-model_underscore = 'risky_attribute'
-instance = risky_attribute

-is_root = false if local_assigns[:is_root].nil?
-is_editable = false if local_assigns[:is_editable].nil?

-seen_ids = [] if local_assigns[:seen_ids].nil?
-id_prefix = "object-#{instance.id}" if local_assigns[:id_prefix].nil?

-seen_this = seen_ids.include?(instance.id)

-risks = instance.risks

-expand_this = risks.count > 0

-summary_toggle_target = "#{id_prefix}-summary"
-objects_toggle_target = "#{id_prefix}-objects"

-main_toggle_target = expand_this ? objects_toggle_target : summary_toggle_target

%li.riskyattribute
  .item-main
    -if !is_root
      .openclose{ :class => !expand_this && 'lastchild' }
    .item-title{ :class => is_root && 'active' }
      .row-fluid
        =render :partial => 'object_leaf', :locals => { :instance => instance }
      .item-actions
        -if is_editable
          %a.btn.btn-mini.halfopacity{ "rel" => "tooltip", "data-placement" => "left", "title" => "Edit this object", 'data-modal-class' => 'modal-wide', 'data-form-target' => 'refresh', "data-toggle" => "modal-ajax-form", :href => url_for(:id => instance.id, :action => :edit, :controller => model_underscore.pluralize, :only_path => true) }
            %i.grcicon-edit
        %a.btn.btn-mini.halfopacity{ :href => list_edit_flow_risk_risky_attributes_path(:risky_attribute_id => instance.id), :'data-toggle' => 'modal-ajax-relationship-selector', :'data-modal-reset' => 'reset', :'data-list-target' => 'refresh', :rel => 'tooltip', :title => 'Link risks to this risky attribute', :'data-modal-class' => 'modal-wide' }
          %i.grcicon-link
        %a.btn.btn-mini.halfopacity{ "rel" => "tooltip", "data-placement" => "left", "title" => "Go to this object's page", :href => flow_risky_attribute_path(instance.id) }
          %i.grcicon-arrowright-black
  .item-content{ :class => is_root && 'in' }
    -if risks.count > 0
      %ul.tree-structure
        -risks.each_with_index do |risk, i|
          =render :partial => 'risk_tree', :locals => { :risk => risk, :id_prefix => "#{id_prefix}-risk-#{risk.id}" }
